# -*- coding: utf-8 -*-
import cgi
import datetime
import wsgiref.handlers

from google.appengine.ext import db


import enhancedModel as em

import models.shippingOrder as som
import models.manifest as mm

class TIModel( em.EnhancedModel ):
    __prefix__ = 'TI'
  
    time = db.DateTimeProperty(auto_now_add=True)
    status = db.IntegerProperty(required=True)
    shippingOrder = db.IntegerProperty(required=True)
    manifest = db.IntegerProperty(required=False)
    sender = db.StringProperty()
    position = db.GeoPtProperty()
    positionText = db.StringProperty()
    comment = db.StringProperty(required=False)    

    def getShippingOrder(self):
        return em.EnhancedModel.queryLatest(som.SOModel, self.shippingOrder).get()
        
    def getManifest(self):
        return em.EnhancedModel.queryLatest(mm.ManifestModel, self.manifest).get()

    def showLink(self):
        return ("/ti/show1/id/%d" % self.ident)

    def editLink(self):
        return ("/ti/edit/id/%d" % self.ident)

    def newLink(self):
        return "/ti/new"

    def deleteLink(self):
        return ("/ti/delete/id/%d" % self.ident)

    #
    # TODO: zmiana ze Stringa na status wybrany z listy
    # nie ustalony sposob implementacji, patrz: 
    # http://code.google.com/p/ii-project-x/issues/detail?id=18
    #
    
